<template>
	<view class=" u-text-center"
		style="background: linear-gradient(180deg,#5A53CE, #5A53CE);display: inline-block;width: 750rpx;min-height: 100vh">



		<view class="u-flex  u-row-between u-padding-20 u-margin-top-40">
			<view class="block" @click="current=0" :class="current==0?'current':''">
				<image :src="$ftpUrl('/meituan1.png')" style="width: 60rpx;height: 60rpx;"></image>
				<image :src="$ftpUrl('/dazhong2.png')" style="width: 60rpx;height: 60rpx;"></image>
				<text class="u-margin-left-10">美团/点评</text>
			</view>
			<view class="block" @click="current=1" :class="current==1?'current':''">
				<image :src="$ftpUrl('/douyin.png')" style="width: 60rpx;height: 60rpx;"></image>
				<text class="u-margin-left-10">抖音团购券</text>
			</view>
		</view>

		<view class=" u-margin-top-40 u-margin-bottom-40 u-font-40" style="color: #fff;">{{current==0?'美团':'抖音'}}自助验券</view>

		<u-cell-item :arrow="false" hover-class="none" :border-bottom="false">
			<u-input v-model="code" placeholder="点击输入卡券兑换码" :clearable="false"
				:customStyle="{fontSize:'26rpx',background:'#403A99',padding:'20rpx',borderRadius:'10rpx',color:'#fff'}"></u-input>
			<view slot="right-icon"   style="position: absolute;right: 0;right: 40rpx;z-index: 999;;">
				<u-icon name="scan" size="40" color="#fff" @click="scan"></u-icon>
			</view>
		</u-cell-item>

		<u-button @click="charge"
			:custom-style="{background:'#598BFE',color:'#fff',fontSize:'28rpx',marginTop:'40rpx',width:'200rpx'}">
			验券开台
		</u-button>
		
		
		
		
		<view class="u-text-left u-margin-top-40  u-border-top" style="color: #C5C4DB;line-height: 50rpx;padding: 20rpx;">
			
			1、请注意所选门店是否为您所购券的门店，以免误选无法正常核销。</br>
			2、输入券码或点击识图验券，选择券二维码图片进行验证，验证通过即可立即开台。</br>
			3、团购券皆为虚拟商品，核销后概不负责退还。</br>
		</view>

<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				code: '',
				object_id: "",
				current: 0,
				id:'',
				cid:''
			}
		},
		onLoad(options) {
			if(options.sid){
				this.id=options.sid
			}
			if(options.cid){
				this.cid=options.cid
			}
		},
		methods: {
			charge() {
				this.$u.post('/user/couponExchange', {
					code: this.code,
					qd:this.current?1:2,
					id:this.id,
					cid:this.cid
				}).then(res => {
					this.stareOrder(res)
					this.code = ''
				})
			},
			stareOrder(id){
				this.$u.post('/indent/orderStart', {
					carport_id:	this.cid,
					member_card_id:id
				}).then(res => {
					this.$refs.uToast.show({
						title: "验券成功",
						type: 'success',
						callback: () => {
							uni.switchTab({
								url:"/pages/my/bookList"
							})
						}
					})
				})
			},
			scan() {
				uni.scanCode({
					success: (res => {
						
						this.$u.post('/user/couponExchange', {
							qr: res.result,
							id:this.id,
							qd:this.current?1:2,
							cid:this.cid
							
						}).then(res => {
							this.stareOrder(res)
						})
					})
				})
			}
		}
	}
</script>

<style scoped>
	.block {
		background: #403A99;
		color: #fff;
		border-radius: 10rpx;

		text-align: center;
		padding: 20rpx 30rpx;
		width: 45%;
		align-items: center;
		display: flex;

	}

	.current {
		background: #598BFE;
	}
</style>